##Topic 8 Exercise## ##load in MPG data set from ggplot2## library(ggplot2) #Question 1 #Generate Scatter plot showing the relationship between #City miles per gallon(cty) and engine displacement(displ) plot1<- ggplot(data = mpg, mapping = aes(displ,cty, colour = class))+ geom_point()+ #geom_smooth(method=lm, se = F) + labs(x = "Engine displacement (liters)", y = "City miles per gallon")+ theme(text = element_text(size = 10), legend.position = c(.8,.8)) #Question 2 #Generate box plots showing the relationship between #City miles per gallon(cty) and engine displacement(displ) plot2 <- ggplot(data = mpg, mapping = aes(displ,cty, colour = class))+ geom_boxplot()+ labs(x = "Engine displacement (liters)", y = "City miles per gallon")+ theme(text = element_text(size = 10), legend.position = c(.8,.8)) #Question 3 #combine the above plots into one plot and #save it to a png file with 300 ppi #load Multiplot script from your saved short course files source("X://R course (sponsored by BERD) 2021//PartII// Topic8//multiplot.R") png("Multiplots Q1 Q2.png", width = 5, height = 5, units = "in",res = 300) multiplot(plot1, plot2, cols = 2) dev.off()